package com.hackordie.operations;

import java.io.FileNotFoundException;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.Log4jConfigurer;

import com.hackordie.commons.HackOrDieResult;
import com.hackordie.constants.HackOrDieConstants;
import com.hackordie.exceptions.HackOrDieException;

public abstract class AHackOrDieOperation {

	protected BeanFactory factory;
	protected HackOrDieResult result;
	
	public AHackOrDieOperation() {
		super();
		try {
			Log4jConfigurer.initLogging(Log4jConfigurer.CLASSPATH_URL_PREFIX + HackOrDieConstants.CONF_LOG4J_PATH);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		factory = new ClassPathXmlApplicationContext(HackOrDieConstants.CONF_CLIENT_PATH);
		result = new HackOrDieResult();
	}

	public HackOrDieResult execute() throws HackOrDieException {
		if (checkParameters()) {
			return executeOperation();
		} else {
			return result;
		}
	}

	protected abstract boolean checkParameters();

	protected abstract HackOrDieResult executeOperation() throws HackOrDieException;
}
